package com.september.mongo.entities;
import com.google.code.morphia.Datastore;
import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Reference;
import com.september.util.BaseData;

@Entity
public class Region extends BaseData {

	@Id
	private String code;
	private String utf8name;
	private String acsiiname;
	private String geoNameId;

	@Reference
	private Nation nation;
	
	public Nation getNation() {
		return nation;
	}

	public void setNation(Nation nation) {
		this.nation = nation;
	}

	@Override
	public String[] getOrdreredField() {
		// TODO Auto-generated method stub
		return new String[] { "code", "utf8name", "acsiiname", "geoNameId" };
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getUtf8name() {
		return utf8name;
	}

	public void setUtf8name(String utf8name) {
		this.utf8name = utf8name;
	}

	public String getAcsiiname() {
		return acsiiname;
	}

	public void setAcsiiname(String acsiiname) {
		this.acsiiname = acsiiname;
	}

	public String getGeoNameId() {
		return geoNameId;
	}

	public void setGeoNameId(String geoNameId) {
		this.geoNameId = geoNameId;
	}

	@Override
	public void manageRefernces() {
		Datastore ds = getDs();
		Nation nat = ds.find(Nation.class).field("_id").equal(this.getCode().substring(0,2)).get();
		this.setNation(nat);
		
	}

}
